package com.wkq.controller;

import com.github.pagehelper.PageInfo;
import com.wkq.domain.Orders;
import com.wkq.service.IOrdersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping(value = "/orders")
public class OrdersController {

    @Autowired
    private IOrdersService iOrdersService;

    @RequestMapping(value = "/findAll")
    @ResponseBody
    public ModelAndView findAll (String page, String size) {
        ModelAndView mv = new ModelAndView();
        List<Orders> list = iOrdersService.findAll(page, size);
        PageInfo<Orders> pageInfo = new PageInfo<>(list);
        mv.addObject("pageInfo",pageInfo);
        mv.setViewName("orders-page-list");
        return mv;
    }

    @RequestMapping(value = "/findById")
    @ResponseBody
    public ModelAndView findById (String id) {
        ModelAndView mv = new ModelAndView();
        Orders orders = iOrdersService.findById(Integer.parseInt(id));
        mv.addObject("orders", orders);
        mv.setViewName("orders-show");
        return mv;
    }
}
